//
//  ST_RecommendHomeController.swift
//  btvideo
//
//  Created by mac on 2020/1/10.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SwifterSwift
import SnapKit
import SwiftyUserDefaults






//MARK: - 全局发特质 验证

//弃用
func push_to_push_peculiarity_controller(peculiarity_id:String,navigationController:UINavigationController?) {
    

    if ownPeculiarityCount == 0 && Defaults[.PushPeculiarityGuidance] == false{
        
        
        let vc = ST_PushPeculiarityGuidanceViewController()
                    
        vc.overCurrentContext = true
        
        GlobalPresent(toController: vc)
        
        Defaults[.PushPeculiarityGuidance] = true
        
        return
    }
    
    if FACE_AVATAE_STATE == 4{
        
        let vc = ST_BTHUDController.init(noticeText: "你的头像还在审核中")
        
        GlobalPresent(toController: vc, animated: false)
        
        main_thread_execute(afterDelay: 2.5) {
            vc.dismiss(animated: false, completion: nil)
        }
        
        return
    }
    
    if FACE_AVATAE_STATE == 3{
        
        navigationController?.show_indeterminate_h_u_d()
        
        let param = ["feature_id":peculiarity_id]
                
        JVrequest(PH.fetchCurrPeculiarityNodesApi,parameters:param, success: { (json) in
            
//            print("发布详情调接口:",json)
            
            let data = json["data"]
            
            let dataStr = data["node_list"].rawString() ?? ""
            
            if let willPushNode = [ST_PeculiarityModel].deserialize(from: dataStr)?.first as? ST_PeculiarityModel{
                
                willPushPeculiarity = willPushNode
                
                navigationController?.pushViewController(ST_PushPeculiaritySelectMediaController())
            }
            
            navigationController?.hidden_indeterminate_h_u_d()
            
        }) { (code, err) in
            
            ToastHud(text: err, view: navigationController?.view)
        }
        
        
        
        return
    }
    
    
    ToastDetectFaceTips {
        
        let vc = ST_IdentifiedFaceAlertController.init(title: "必须要通过真实头像认证\n才能进行特质添加", style: ST_IdentifiedFaceAlertStyle.appendPeculiarity)
                    
        vc.overCurrentContext = true
        
        vc.confirm_closure = {
            
            
            if FACE_AVATAE_STATE == 1{
                
                DetectFaceHandle()
                
            }else{
                
                let nav = UINavigationController.create_hiding_bar_navigation_controller(rootViewController: ST_MyPhotoViewController())
                
                GlobalPresent(toController: nav)
                
            }
        }
        return vc
    }
    
    
}



/**
 发布特质 Global 
 */
func push_peculiarity(pecId:String,navigationController:UINavigationController?,hud_controller:UIViewController?) {
    
    
    hud_controller?.show_indeterminate_h_u_d()
    
    let param = ["feature_id":pecId]
            
    JVrequest(PH.fetchCurrPeculiarityNodesApi,parameters:param, success: { (json) in
        
        
        let data = json["data"]
        
        let dataStr = data["node_list"].rawString() ?? ""
        
        if let willPushNode = [ST_PeculiarityModel].deserialize(from: dataStr)?.first as? ST_PeculiarityModel{
            
            willPushPeculiarity = willPushNode
            
            push_peculiarity(navigationController: navigationController, operationController: ST_PushPeculiaritySelectMediaController())
            
        }
        
        hud_controller?.hidden_indeterminate_h_u_d()
        
    }) { (code, err) in
        
        ToastHud(text: err, view: hud_controller?.view)
    }
    
    
}


/**
 发布特质 Global
 */
func push_peculiarity(navigationController:UINavigationController?,operationController:UIViewController) {
    
    if restrictFemaleFace(){
        return
    }
    
    if ownPeculiarityCount == 0 && Defaults[.PushPeculiarityGuidance] == false{
        
        
        let vc = ST_PushPeculiarityGuidanceViewController()
                    
        vc.overCurrentContext = true
        
        GlobalPresent(toController: vc)
        
        Defaults[.PushPeculiarityGuidance] = true
        
        return
    }
    
    
    
    if let nav = navigationController{
        
        nav.pushViewController(operationController)
        
    }else{
        
        let nav =  UINavigationController.create_hiding_bar_navigation_controller(rootViewController: operationController)
        
        GlobalPresent(toController: nav)
    }
    
}


func push_to_push_peculiarity_controller(navigationController:UINavigationController?) {
    
    if ST_BTUserInfoManager.shared.confined_to_ticket(){
        
        let vc = ST_TicketViewController()
        
        vc.from = .mainIndexConfined
        
        GlobalPresent(toController: vc)
        
        return
    }
    
    push_peculiarity(navigationController: navigationController, operationController: ST_PushPeculiarityViewController())
    
}
